﻿<%@ Page Title="Home" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="Testify._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <script type="text/javascript">
        $(document).ready(function () {
            $("#link1").show().animate({
                width: "200px"
            }, 300, function () {
                $("#link2").show().animate({
                    width: "200px"
                }, 300, function () {
                    $("#link3").show().animate({
                        width: "200px"
                    }, 300, function () {
                        $("#currentTermBox").show(300);
                        $("#link4").show().animate({
                            width: "200px"
                        }, 300);
                    });
                });
            });

            $("#MainContent_gv_studentTests").fadeIn(1000);

            //            $("#link1").hover(function () {
            //                $(this).animate({ height: "400px" }, 200);
            //                //$(this).parent().find("a").stop().animate({ height: "100px" }, 200);
            //            }, function () {
            //                $(this).animate({ height: "200px", marginBottom: "20px" }, 300);
            //                //$(this).parent().find("a").stop().animate({ marginTop: "1px", opacity: 1 }, 300);
            //            });
        });
    </script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:Panel ID="pnl_adminView" runat="server" Visible="false">
        <a id="link1" style="width:0;height:200;margin:0px 10px;" href="Courses/AdminActions.aspx"><span class="linkBox"><span class="linkBoxText">Actions</span></span></a>
        <a id="link2" style="width:0;height:200;margin:0px 10px;" class="hidden" href="Courses/Enrollment.aspx"><span class="linkBox"><span class="linkBoxText">Enrollment</span></span></a>
        <a id="link3" style="width:0;height:200;margin:0px 10px;" class="hidden" href="Account/Users.aspx"><span class="linkBox"><span class="linkBoxText">Users</span></span></a>
        <a id="link4" style="width:0;height:200;margin:0px 10px;" class="hidden" href="Tools/Security.aspx"><span class="linkBox"><span class="linkBoxText">Security</span></span></a>
        <div id="currentTermBox" class="hidden">
            <table id="currentTermTable">
                <tr>
                    <td><asp:Label ID="lblCurrentTerm" runat="server" Text="Current Term:" AssociatedControlID="ddlCurrentTerm" /></td>
                    <td>
                        <div class="dropdown">
                            <asp:DropDownList ID="ddlCurrentTerm" runat="server" DataSourceID="dsCurrentTerm" DataTextField="term_name" DataValueField="term_id" ondatabound="ddlCurrentTerm_DataBound" />
                        </div>
                        <asp:SqlDataSource ID="dsCurrentTerm" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                            ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
                            SelectCommand="
SELECT t.term_id, t.term_year || ' ' || tt.term_type_name AS term_name
  FROM term t
       JOIN term_type tt ON (tt.term_type_id = t.term_type_id)
 WHERE t.term_maint != 'D'
 ORDER BY t.term_year, tt.term_type_name" UpdateCommand="
UPDATE environment
   SET current_term_id = :p_NewTermID" >
                            <UpdateParameters>
                                <asp:ControlParameter ControlID="ddlCurrentTerm" Name="p_NewTermID" PropertyName="SelectedValue" />
                            </UpdateParameters>
                        </asp:SqlDataSource>
                    </td>
                    <td><asp:Button ID="btnCurrentTerm" runat="server" Text="Change Current Term" onclick="btnCurrentTerm_Click" CssClass="smallButton" /></td>
                </tr>
            </table>
        </div>
    </asp:Panel>

    <asp:Panel ID="pnl_teacherView" runat="server" Visible="false">
        <a id="link1" style="width:0;height:200;margin:0px 10px;" href="Courses/Classes.aspx"><span class="linkBox"><span class="linkBoxText">Classes</span></span></a>
        <a id="link2" style="width:0;height:200;margin:0px 10px;" class="hidden" href="Tests/CreateTests.aspx"><span class="linkBox"><span class="linkBoxText">Tests</span></span></a>
        <a id="link3" style="width:0;height:200;margin:0px 10px;" class="hidden" href="Tests/AssignTest.aspx"><span class="linkBox"><span class="linkBoxText">Assignments</span></span></a>
        <a id="link4" style="width:0;height:200;margin:0px 10px;" class="hidden" href="Grades/GradeStatistics.aspx"><span class="linkBox"><span class="linkBoxText">Statistics</span></span></a>
    </asp:Panel>

    <div class="container">        
        <asp:Panel ID="pnl_studentView" runat="server" Visible="false">
            <asp:SqlDataSource ID="src_studentTests" runat="server" 
                ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
                SelectCommand="select test.test_name, course_type_prefix || ' ' || course_number || '-' || section_number || ': ' || course_name AS course_name,
                                    test.test_id as test_id, assignment.assignment_id as assign_id, TO_CHAR(assignment_start, 'MM/DD/YYYY HH:MI AM') AS assign_start
                               from enrollment e
                               join section s using (section_id)
                               join class c using (class_id)
                               join course crs using (course_id)
                               join assignment using (section_id)
                               join test on test.test_id = assignment.test_id
                               join course_type using (course_type_id)
                               where student_id = :p_StudentID
                                 and test.test_maint != 'D'
                                 and sysdate &lt; assignment_end
                                 AND c.term_id = (SELECT current_term_id FROM environment)
                                 AND NOT EXISTS (SELECT 1 FROM response r WHERE r.assignment_id = assignment.assignment_id AND r.student_id = :p_StudentID)
                                order by assignment_start">
                <SelectParameters>
                    <asp:SessionParameter Name="p_StudentID" SessionField="UserID" />
                </SelectParameters>
            </asp:SqlDataSource>

            <asp:Label ID="lblWaitError" CssClass="failureNotification" runat="server" Text="That test has not started yet." Visible="false"></asp:Label>

            <asp:GridView ID="gv_studentTests" CssClass="hidden" runat="server" AutoGenerateColumns="False" DataSourceID="src_studentTests" EmptyDataText="You have no tests.">
                <Columns>
                    <asp:BoundField DataField="TEST_NAME" HeaderText="Your Tests" SortExpression="TEST_NAME" />
                    <asp:BoundField DataField="COURSE_NAME" HeaderText="" SortExpression="COURSE_NAME" />
                    <asp:BoundField DataField="assign_start" HeaderText="" SortExpression="assign_start" />
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:LinkButton ID="lb_giveTest" CssClass="btn_details btn_giveTest" runat="server" Text="Take Test" OnClick="giveTest" CommandArgument='<%# Bind("test_id") %>' CommandName='<%# Bind("assign_id") %>'></asp:LinkButton>
                            <asp:ConfirmButtonExtender ID="cbe_giveTest" TargetControlID="lb_giveTest" 
                                runat="server" DisplayModalPopupID="customConfirm">
                            </asp:ConfirmButtonExtender>
                            <asp:ModalPopupExtender ID="customConfirm" runat="server"
                                TargetControlID="lb_giveTest" PopupControlID="custom_panel" 
                                OkControlID="btn_ok" CancelControlID="btn_cancel"
                                BackgroundCssClass="modalBackground" >
                            </asp:ModalPopupExtender>
                            <asp:Panel ID="custom_panel" runat="server" CssClass="modalDialog">
                                <div class="modalBackground">
                                    Are you sure you want <br />to take this test?
                                    <br /><br />
                                    <asp:Button ID="btn_ok" class="modalButton" runat="server" Text="Yes" />
                                    <asp:Button ID="btn_cancel" class="modalButton" runat="server" Text="No" />
                                </div>
                            </asp:Panel>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </asp:Panel>

    </div>
</asp:Content>


